package com.persagy.job.test;

import java.util.Date;

import javax.annotation.Resource;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.persagy.ems.pojo.quartz.JobErrorLog;
import com.persagy.ems.pojo.quartz.ScheduleJob;
import com.persagy.service.quartz.ScheduleJobService;

@DisallowConcurrentExecution
public class MyScheduleJob2 implements Job {
	
	@Resource
	private ScheduleJobService scheduleJobService;
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		ScheduleJob detailInfo = (ScheduleJob)context.getMergedJobDataMap().get("scheduleJob");
		System.out.println("任务成功开始运行,任务名称 = [" + detailInfo.getJobName()+ "]");
		try {
			for(int i=0;i<6;i++){
				Thread.sleep(1000);
				System.out.println("任务正在运行 = [" + detailInfo.getJobName()+ "]");
			}
			
		} catch (Exception e) {
			JobErrorLog error = new JobErrorLog();
			error.setJobName(detailInfo.getJobName());
			error.setError(detailInfo.getJobName());
			error.setTime(new Date());
			scheduleJobService.insertErrorLog(error);
		}
        System.out.println("任务结束,任务名称 = [" + detailInfo.getJobName()+ "]");
	}
	
}
